package com.demo.activityservicedemo.threadpool

import android.os.Bundle
import android.os.Handler
import android.os.Looper
import android.os.SystemClock
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import com.demo.activityservicedemo.R

/**
 * Created by zhangyuncai on 2024/6/26.
 * 为验证线程池中当有一个线程池是while死循环时，其他线程是否还能工作。结论是：无法工作
 */
class ThreadPoolActivity : AppCompatActivity() {
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_threadpool)

        start2()
        ThreadPoolManager.execute(thread1)
    }

    fun start2(){
        Log.e("test","start2")
        Handler(Looper.getMainLooper()).postDelayed({
            ThreadPoolManager.execute(thread2)
            ThreadPoolManager.execute(thread3)
            start2()
        }, 3 * 1000)
    }

    val thread1 = object : Thread() {
        override fun run() {
            while (true) {
            }
        }
    }

    val thread2 = object : Thread() {
        override fun run() {
            Log.e("test:", "haha")
        }
    }

    val thread3 = object : Thread() {
        override fun run() {
            Log.e("test:", "haha3")
        }
    }
}